TE32K is designed to be a more-or-less “plug in” replacement for the Macintosh Toolbox TextEdit package. The major difference between the two editor packages is that TE32K allows for the manipulation of text-files LARGER than 32K. There are a few other differences as well, most of which are shortcomings due to laziness on my part, but since this source code is provided to you gratis, please feel free to modify it in whatever twisted way your warped little heart desires. If you do improve it in any way, please be kind enough to share your work with the rest of us (i.e. send me a copy so I can keep track of TE32K's current state of evolution!).
Note that TE32K is written as a non-OOP C program. If this is not what you're interested in, I suggest you take a look at the many excellent OOP TextEdit replacement clas libraries available via FTP.
I wrote TE32K since I needed it for rnMac, a Macintosh newsreader I wrote. Well, I didn't really need it, but it was nice to have, and I wasn't doing anything one afternoon, so.....
Legal Stuff:
============
TE32K is provided free of charge, since no-one will ever pay me anything for it anyway. However, if you do use TE32K in a piece of software which you market, for every copy you sell, you are required to donate $1.00 to the World Wildlife Fund, 90 Eglinton Avenue East, Suite 504, Toronto, Ontario, Canada, M4P 2Z7.
Using TE32K:
============
TE32K is designed as a source-level replacement for TextEdit. This means that you will have to compile the “TE32K.c” file along with the rest of your program. As well, you will have to change all your TextEdit calls to the equivalent TE32K routines. The TE32K function calls and data structures are declared in the file “TE32K.h” which you should #include in your source, too. The data structures and interface calls are described in the following sections.
TE32K Data Structures:
======================
TE32K uses a couple of unconventional data stuctures to work its magic; these are defined in the “TE32K.h” header file as follows:
/* a Rect defined with long's, rather than int's */
typedef struct
{
long top,left,bottom,right;
} LongRect;
/* a Point defined with long's rather than int's */
typedef struct
{
long h,v;
} LongPoint;
/* the TE32K data structure! Notice the standard TextEdit field names! */
typedef pascal Boolean (*TE32KProcPtr)(void);
typedef struct
{
LongRect destRect; /* the destination rectangle */
LongRect viewRect; /* the view rectangle */
int lineHeight; /* height of a line of text */
int fontAscent; /* the font ascent */
LongPoint selPoint; /* the coords of the selection point */
long selStart; /* the start of the selected text */
long selEnd; /* the end of the selected text */
int active; /* active flag */
TE32KProcPtr clikLoop; /* hook for the click-loop routine */
long clickTime; /* time used for double-clicking */
long clickLoc; /* location of last click, maybe */
long caretTime; /* time for blinking cursor */
int caretState; /* state of cursor (invisible/showing) */
long teLength; /* size of edit text */
Handle hText; /* Handle to text */
int txFont; /* the font */
char txFace; /* the font face */
int txMode; /* the text display mode */
int txSize; /* the size of the text */
int tabWidth; /* the width of tabs */
int crOnly; /* do Carriage Return only? */
GrafPtr inPort; /* the GrafPort we're in */
long nLines; /* the number of lines of text */
int theCharWidths[256]; /* quick and dirty lookup table */
long lineStarts[]; /* the line starts array */
} TE32KRec,*TE32KPtr,**TE32KHandle;
If you've done any programming with TextEdit, you'll quickly realize that these data structures are pretty easy to figure out . Basically, I've just enlarged the relevant field sizes from int's to long's, and thrown away the fields I didn't need. All the fields of the TE32KRec are named the same as traditional TextEdit fields, so it should be pretty simple to modify your source code to be compatible with TE32K. The programs I've used it in were written to use TextEdit originally, but it's taken me no more than half an hour to make them compatible with TE32K. If this seems too much effort for you, maybe you should stick with TextEdit then.
Oh— right now the crOnly field is defined such that if it is zero, word-wrapping is performed (the default set by TE32KNew), and if it is non-zero, lines are broken only at carriage returns. Should I change this to be exactly the same as TextEdit? Does anyone really care?
TE32K Interface Calls:
======================
All the public routines are described as follows, with the equivalent TextEdit routine listed below the TE32K function declaration. The names of each routine are basically the same as the standard TextEdit routines albeit with the “TE” replaced by “TE32K”. The parameters are pretty much the same as usual too, with the major difference being the use of long's in place of int's, etc.
Respond to a mouse-down event in the view rectangle, extend indicates whether the shift-key was depressed and thus whether the user is selecting a range of text
Returns in selPt the coordinates of the character specified by selIndex. Right now, there's a problem with placing the cursor at the end of a wrapped line— instead, the cursor is placed at the start of the next line. Sigh, this one is going to be messy to clear up....
long TE32KGetOffset(LongPoint *selPt,TE32KHandle theTE32KHandle);
Use to set the font, face, mode, and size of the text record and update the quick-and-dirty table of character widths used in word-wrapping calculations. If you change the fields of the TE32KHandle on your own, things will get nasty!
void SetLongRect(LongRect *,long,long,long,long);
-------------------------------------------------
unique to TE32K
Use to set the left, top, right, bottom of a LongRect; similar to SetRect
void LongRectToRect(LongRect *,Rect *);
-------------------------------------------------
unique to TE32K
Convert a LongRect to a simple Rect, clipping the size if necessary
void RectToLongRect(Rect *,LongRect *);
-------------------------------------------------
unique to TE32K
Convert a Rect to a LongRect
Phew, still with me? Well, as promised, they're pretty much identical to their TextEdit counterparts, and modifying your source to be compatible should be a breeze, more or less. Just watch out for the use of long's in place of int's. (And yes, I know you don't like the way I keep inflecting “long” to indicate plurality. And I agree; it does make me look like a dummy who doesn't know anything about the possessive case, but my Canadian Writer's Handbook says that it's okay to use an apostrophe to indicate plurality for short little weird words, so I'm going to continue doing it.)
TE32K Demo:
===========
So, you'd like to actually see TE32K in action? Well, with the source code for TE32K, I've included a little application that allows you to open and edit text files using TE32K instead of TextEdit. Heck, I even include the source code so you can muck around with it yourself! It was written using Symantec's Think C, version 5.0.2 (or whatever the version number is). I used the demo to write this document, so it sort of even works!